package com.example.shopping.repository;

import com.example.shopping.entity.Goods;
import com.example.shopping.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface GoodsRepository extends JpaRepository<Goods,String> {
    Goods findByGid(String gid);


    @Query(value = "SELECT * FROM goods g " +
            "WHERE (:goodsname IS NULL OR LOWER(g.goodsname) LIKE LOWER(CONCAT('%', :goodsname, '%'))) " +
            "AND (:gid IS NULL OR g.gid = :gid) " +
            "AND (:goodstype IS NULL OR g.tcode = :goodstype)",
            nativeQuery = true)
    Page<Goods> findGoods(@Param("goodsname") String goodsname,
                          @Param("gid") String gid,
                          @Param("goodstype") String goodstype,
                          Pageable pageable);
}
